package category.controller;

import java.util.List;
import java.util.HashMap;
import java.util.Map;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import com.aidex.framework.cache.DictUtils;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import category.domain.BCategory;
import category.service.BCategoryService;

/**
 * 商品类目表Controller
 * @author 1205560870@qq.com
 * @email 1205560870@qq.com
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/category/bCategory")
public class BCategoryController extends BaseController {

    @Autowired
    private BCategoryService bCategoryService;

    /**
     * 查询商品类目表列表
     */
    @PreAuthorize("@ss.hasPermi('category:bCategory:list')")
    @GetMapping("/list")
    public R<PageInfo> list(BCategory bCategory, HttpServletRequest request, HttpServletResponse response) {
        bCategory.setPage(new PageDomain(request, response));
        return R.data(bCategoryService.findPage(bCategory));
    }

    /**
     * 获取商品类目表详细信息
     */
    @PreAuthorize("@ss.hasPermi('category:bCategory:query')")
    @GetMapping(value = "/{id}")
    public R<BCategory> detail(@PathVariable("id") String id) {
        return R.data(bCategoryService.get(id));
    }

    /**
     * 新增商品类目表
     */
    @PreAuthorize("@ss.hasPermi('category:bCategory:add')")
    @Log(title = "商品类目表", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  BCategory bCategory) {
        return R.status(bCategoryService.save(bCategory));
    }

    /**
     * 修改商品类目表
     */
    @PreAuthorize("@ss.hasPermi('category:bCategory:edit')")
    @Log(title = "商品类目表", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BCategory bCategory) {
        return R.status(bCategoryService.save(bCategory));
    }

    /**
     * 删除商品类目表
     */
    @PreAuthorize("@ss.hasPermi('category:bCategory:remove')")
    @Log(title = "商品类目表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(bCategoryService.deleteBCategoryByIds(ids));
    }


    /**
     * 导出商品类目表列表
     */
    @PreAuthorize("@ss.hasPermi('category:bCategory:export')")
    @Log(title = "商品类目表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BCategory bCategory) {
        List<BCategory> list = bCategoryService.findList(bCategory);
        ExcelUtil<BCategory> util = new ExcelUtil<BCategory>(BCategory.class);
        return util.exportExcel(list, "商品类目表数据");
    }
	
    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }

}
